package com.eastfair.enums;

import com.eastfair.annotation.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * <p>
 * 排序枚举类
 *
 * </p>
 *
 * @author zjn
 * @date 2021-07-29
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "SortTypeEnum", description = "排序 #{ASC:升序;DESC:降序;枚举")
public enum SortTypeEnum implements BaseEnum {

    /**
     * CN="中文"
     */
    ASC("升序"),
    /**
     * EN="英文"
     */
    DESC("降序"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static SortTypeEnum match(String val, SortTypeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static SortTypeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(SortTypeEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "ASC,DESC", example = "ASC")
    public String getCode() {
        return this.name();
    }

}
